package cn.baiweigang.uu.service.linearswap;

import cn.baiweigang.uu.enums.StrategyStatusEnum;
import cn.baiweigang.uu.model.StrategyInfo;
import cn.baiweigang.uu.utils.DateUtil;
import cn.baiweigang.uu.utils.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GuardService {
    @Autowired
    private StrategyService strategyService;

    public void checkAutoAvailable(StrategyInfo strategyInfo) {
        LogUtil.logDebug("稳定性检查");
        if (strategyInfo == null) {
            LogUtil.logInfo("strategy尚未初始化好");
            return;
        }
        if (strategyInfo.getCurrentStrategyStatus() == StrategyStatusEnum.INIT ||
                strategyInfo.getCurrentStrategyStatus() == StrategyStatusEnum.OPEN_ORDER_DEAL) {
            return;
        }
        //当前策略状态停留超过30分钟，重新初始化
        if (DateUtil.getTs() - strategyInfo.getDateTimeTs() > 30 * 60 * 1000) {
            String memo = "当前不是禁止开仓时间  且策略状态停留超过30分钟，重新初始化";
            LogUtil.logInfo(memo);
            strategyInfo = strategyService.init(strategyInfo.getAccountInfo());
        }
    }
}
